<template>
  <div :class="themeClass">
    <el-container class="app-container">
      <el-header>
        <el-row class="headMenu">
          <el-col
            :span="12"
            class="headColor"
            style="position: relative;">
            <div class="anSteel"/>
            <div style="position: absolute;left: 214px;font-size: 12px;color: #409EFF;">
              <!--<div>{{ webData }}</div>-->
              <el-menu
                v-if="false"
                :default-active="currentPath"
                mode="horizontal"
                router>
                <template v-for="(item, index) in levelList">
                  <el-submenu
                    v-if="item.children != undefined && item.children.length > 0"
                    :key="index+'item.label'"
                    :index="item.id">
                    <template slot="title">
                      <i :class="item.icon"/>
                      <span>{{ item.label }}</span>
                    </template>
                    <el-menu-item
                      v-for="(itemChild, indexChild) in item.children"
                      :key="indexChild + 'menuC'"
                      :index="itemChild.path">
                      <span slot="title">{{ itemChild.label }}</span>
                    </el-menu-item>
                  </el-submenu>

                  <el-menu-item
                    v-else
                    :index="item.path"
                    :key="index+'item.label'">
                    <template slot="title">
                      <i :class="item.icon"/>
                      <span>{{ item.label }}</span>
                    </template>
                  </el-menu-item>
                </template>
              </el-menu>
            </div>
          </el-col>
          <el-col :span="12" class="headColor" style="text-align: right;">
            <el-divider direction="vertical"></el-divider>
            {{ username }}
          </el-col>
        </el-row>
      </el-header>
      <el-row>
        <el-col v-if="isMenu" :span="3" style="width: 200px;height: calc(100vh - 62px);overflow-y: auto" class="barStyel leftMenu">
          <el-menu
            v-if="levelList.length>0"
            :default-active="currentPath"
            mode="vertical"
            router
            style="height: 100%;">
            <div v-for="(item, index) in levelList" :key="index + 'menuV'">
              <el-submenu
                v-if="item.children != undefined && item.children.length > 0"
                :index="item.id">
                <template slot="title">
                  <i :class="item.icon"/>
                  <span>{{ item.label }}</span>
                </template>
                <template
                  v-for="(itemChild, indexChild) in item.children">
                  <el-submenu
                    v-if="itemChild.children != undefined && itemChild.children.length > 0"
                    :key="indexChild + 'menuC'"
                    :index="itemChild.id">
                    <template slot="title">
                      <i :class="itemChild.icon"/>
                      <span>{{ itemChild.label }}</span>
                    </template>
                    <el-menu-item
                      v-for="(itemChild2, indexChild2) in itemChild.children"
                      :key="indexChild2 + 'menuC'"
                      :index="itemChild2.path">
                      <span slot="title">{{ itemChild2.label }}</span>
                    </el-menu-item>
                  </el-submenu>
                  <el-menu-item
                    v-else
                    :key="indexChild + 'menuC'"
                    :index="itemChild.path">
                    <span slot="title">{{ itemChild.label }}</span>
                  </el-menu-item>
                </template>
              </el-submenu>

              <el-menu-item v-else :index="item.path">
                <template slot="title">
                  <i :class="item.icon"/>
                  <span>{{ item.label }}</span>
                </template>
              </el-menu-item>
            </div>
          </el-menu>
        </el-col>
        <el-col
          :span="isMenu ? 21 : 24"
          :style="isMenu ? 'width: calc(100% - 200px);' : ''"
          style="height: calc(100vh - 61px);overflow-y: auto;padding: 10px;"
          class="xw_contain barStyel">
          <nuxt />
        </el-col>
      </el-row>
    </el-container>
  </div>
</template>
<script>
import { post } from "@/lib/Util";
import _ from "lodash";
import { menuData } from "@/lib/ApiURL";
export default {
  head() {
    return {
      title: this.title,
      meta: [
        {
          name: "keywords",
          content: "首页"
        }
      ]
    };
  },
  data() {
    return {
      isMenu: true,
      theme: "them-deep",
      username: "",
      user: "",
      menu: [],
      menuV: [],
      levelList: [],
      level: 0,
      currentPath: "",
      isHeadData: ""
    };
  },
  computed: {
    themeClass() {
      return `theme-${this.theme}`;
    }
  },
  watch: {
    $route: {
      handler: function(val, oldVal) {
        this.menu = menuData;
        if (val.path === "/") {
          this.currentPath = val.path;
        } else {
          if (global.localStorage !== undefined) {
            global.localStorage.setItem("path", val.path);
          }
          this.currentPath = val.path;
        }
      },
      // 深度观察监听
      deep: true,
      immediate: true
    }
  },
  mounted() {
    this.levelList = menuData;
    console.log("路由", this.$router);
  },
  methods: {
    // 修改主题
    changeThem(command) {
      this.theme = command;
      window.localStorage.setItem("pageThem", command);
      window.location.reload();
    }
  }
};
</script>
<style>
html,
body {
  font-family: "Source Sans Pro", -apple-system, BlinkMacSystemFont, "Segoe UI",
    Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  word-spacing: 1px;
  -ms-text-size-adjust: 100%;
  -webkit-text-size-adjust: 100%;
  -moz-osx-font-smoothing: grayscale;
  -webkit-font-smoothing: antialiased;
  box-sizing: border-box;
}

*,
*:before,
*:after {
  box-sizing: border-box;
  margin: 0;
}
.xw_nercar {
  float: right;
  padding: 14px 7px 0px 10px;
}
.el-header {
  padding: 0px 10px 0px 0px !important;
}
.anSteel {
  float: left;
  width: 300px;
  height: 100%;
  background-image: url("@/assets/img/ningSteel.png");
  background-repeat: no-repeat;
  background-size: 80%;
  background-position: center;
  background-position-x: 8px;
}
</style>
